package com.atguigu.gulimall.product;

import java.util.Arrays;

public class test01 {

    public static void main(String[] args) {
        int arr[] = {139,24,109,1,30,60,15,-1};
        System.out.println(Arrays.toString(arr));
        test01(arr);

    }
    //选择排序
    public static void test01(int arr[]){
        for (int i = 0; i <arr.length-1; i++) { //循环数组n-1次
            int min = arr[i]; //假设数组最小值为第一个
            int minIndex = i; //数组最小值的索引下标
            for(int j = i+1;j<arr.length;j++){
                if (min>arr[j]){
                    min = arr[j];//重置数组最小值
                    minIndex = j; //重置数组最小索引
                }
            }
            if (minIndex!=i){
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
            System.out.println(Arrays.toString(arr));

        }
    }
}

